package com.tingyuge.thinking.spring.configuration.metadata;

import com.tingyuge.thinking.spring.ioc.overview.domain.User;
import com.tingyuge.thinking.spring.ioc.overview.enums.City;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

import java.util.Map;

/**
 * @author xiaodao
 * @version 1.0
 * @date 2021/8/22
 */
@PropertySource(name = "yamlPropertySouce",
    value="classpath:/META-INF/user.yaml" ,
        factory = YamlProperSourceFactory.class
)
public class AnnotationYamlPropertiesSourceDemo {


    @Bean
    public User user(@Value("${user.id}" ) Long id, @Value("${user.name}" )String name, @Value("${user.city}")City city){

        User user = new User();
        user.setId(id);
        user.setName(name);
        user.setCity(city);
        return user;
    }

    public static void main(String[] args) {

        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(AnnotationYamlPropertiesSourceDemo.class);
        applicationContext.refresh();
        User bean = applicationContext.getBean(User.class);
        System.out.println(bean);

    }
}
